﻿using System.Windows.Forms;
using System.Linq;
using System;
using log4net;
using System.Reflection;

namespace SopCastRecorder
{
	public partial class ScheduleHeaderControl : UserControl
	{
		private static ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

		private bool isAscOrderByPath;
		private bool isAscOrderByChannel;
		private bool isAscOrderByTime;
		private bool isAscOrderByWeek;
		public Action<bool> OrderByPath { get; set; }
		public Action<bool> OrderByChannel { get; set; }
		public Action<bool> OrderByTime { get; set; }
		public Action<bool> OrderByWeek { get; set; }

		public ScheduleHeaderControl()
		{
			InitializeComponent();
		}

		private void lblPath_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.Path();
			}
			catch (Exception exception1)
			{
				logger.Error(MethodBase.GetCurrentMethod().Name, exception1);
				Form1.SetErrorStatus();
			}
		}

		private void Path()
		{
			this.isAscOrderByPath = !this.isAscOrderByPath;
			this.isAscOrderByChannel = false;
			this.isAscOrderByTime = false;
			this.isAscOrderByWeek = false;
			this.OrderByPath.Invoke(this.isAscOrderByPath);
		}

		private void lblChannel_Click(object sender, EventArgs e)
		{
			try
			{
				this.Channel();
			}
			catch (Exception exception1)
			{
				logger.Error(MethodBase.GetCurrentMethod().Name, exception1);
				Form1.SetErrorStatus();
			}
		}

		private void Channel()
		{
			this.isAscOrderByPath = false;
			this.isAscOrderByChannel = !this.isAscOrderByChannel;
			this.isAscOrderByTime = false;
			this.isAscOrderByWeek = false;
			this.OrderByChannel.Invoke(this.isAscOrderByChannel);
		}

		private void lblTime_Click(object sender, EventArgs e)
		{
			try
			{
				this.Time();
			}
			catch (Exception exception1)
			{
				logger.Error(MethodBase.GetCurrentMethod().Name, exception1);
				Form1.SetErrorStatus();
			}
		}

		private void Time()
		{
			this.isAscOrderByPath = false;
			this.isAscOrderByChannel = false;
			this.isAscOrderByTime = !this.isAscOrderByTime;
			this.isAscOrderByWeek = false;
			this.OrderByTime.Invoke(this.isAscOrderByTime);
		}

		private void lblWeek_Click(object sender, EventArgs e)
		{
			try
			{
				this.Week();
			}
			catch (Exception exception1)
			{
				logger.Error(MethodBase.GetCurrentMethod().Name, exception1);
				Form1.SetErrorStatus();
			}
		}

		private void Week()
		{
			this.isAscOrderByPath = false;
			this.isAscOrderByChannel = false;
			this.isAscOrderByTime = false;
			this.isAscOrderByWeek = !this.isAscOrderByWeek;
			this.OrderByWeek.Invoke(this.isAscOrderByWeek);
		}
	}
}
